package Entity;

import java.util.*;

import Controller.DBcontroller;

/**
 * This is one of the reports.
 * this report is for performance, and it will be produced to the company manager.
 * @author Shahar Shelli
 *
 */
public class PerformanceReport extends Report
{
	private Date start;
	private int [] NumOfSubs;
	private int[] SubsMoreCar;
	
	/**
	 * is the constructor. it will call the super constructor 
	 * and also set the number of subscriptions and number of subscriptions that have more that one car.
	 * @param s= the start date.
	 * @param e= the end date. e and s will determine the period of time.
	 * @param des= the description for the report.(optional that's why we need this constructor)
	 */
	public PerformanceReport(Date s,Date e,String desc)
	{
		super(e,desc);
		this.NumOfSubs=new int[6];
		this.SubsMoreCar=new int[6];
		for(int i=0; i<6; i++)
		{
			this.NumOfSubs[i]=DBcontroller.getNumOfSubs(i+1);
			this.SubsMoreCar[i]=DBcontroller.getNumOfSubsWithMoreThen1Car(i+1);
		}
		this.start=s;
	}
	
	/**
	 * is the constructor. it will call the super constructor 
	 * and also set the number of subscriptions and number of subscriptions that have more that one car.
	 * @param s= the start date.
	 * @param e= the end date. e and s will determine the period of time.
	 */
	public PerformanceReport(Date s,Date e)
	{
		super(e,"");
		this.NumOfSubs=new int[6];
		this.SubsMoreCar=new int[6];
		for(int i=0; i<6; i++)
		{
			this.NumOfSubs[i]=DBcontroller.getNumOfSubs(i+1);
			this.SubsMoreCar[i]=DBcontroller.getNumOfSubsWithMoreThen1Car(i+1);
		}
		this.start=s;
	}
	
	/**
	 * is a function for validate the input. it will only check that the start date is before the end date.
	 * @param s= start date.
	 * @param e= end date.
	 * @param des= the description 
	 * @param p= parking lot number.
	 * @return true or false if everything is ok.
	 */
	public boolean Validate(Date s,Date e,String desc,int p)
	{
		if(s.after(e))
			return false;
		return true;
	}
	
	// the get functions.
	public Date getStart() {
		return start;
	}
	
	public int getNumOfSubsMed()
	{
		Arrays.sort(this.NumOfSubs);
		return this.NumOfSubs[this.NumOfSubs.length/2];
	}
	
	public int getSubsMoreCarMed()
	{
		Arrays.sort(this.SubsMoreCar);
		return this.SubsMoreCar[this.SubsMoreCar.length/2];
	}
	
	public int getNumOfSubs(int p) {
		return NumOfSubs[p-1];
	}
	
	public int getSubsMoreCar(int p) {
		return SubsMoreCar[p-1];
	}
	
	public int[] getSubsFrequencyDist()
	{
		Arrays.sort(this.NumOfSubs);
		int[]arr=new int[this.NumOfSubs[this.NumOfSubs.length-1]]; for(int k=0; k<arr.length; k++) arr[k]=0;
		for(int i=0; i<this.NumOfSubs.length; i++)
			arr[this.NumOfSubs[i]-1]++;
		return arr;
	}
	
	public int[] getSubsMoreCarFrequencyDist()
	{
		Arrays.sort(this.SubsMoreCar);
		int[]arr=new int[this.SubsMoreCar[this.SubsMoreCar.length-1]]; for(int k=0; k<arr.length; k++) arr[k]=0;
		for(int i=0; i<this.SubsMoreCar.length; i++)
			arr[this.SubsMoreCar[i]-1]++;
		return arr;
	}
}

